/*
 * Artificial Intelligence for Humans
 * Volume 1: Fundamental Algorithms
 * Scala Version
 * http://www.aifh.org
 * http://www.jeffheaton.com
 *
 * Code repository:
 * https://github.com/jeffheaton/aifh

 * Copyright 2013 by Jeff Heaton
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * For more information on Heaton Research copyrights, licenses
 * and trademarks visit:
 * http://www.heatonresearch.com/copyright
 */
package com.heatonresearch.aifh.randomize

import com.heatonresearch.aifh.AIFH
import org.scalatest.Suite
import org.scalatest.matchers.ShouldMatchers

/**
 * Test MWC random.
 */
object TestMultiplyWithCarryGenerateRandom {
  val BOOLEAN_TEST = List(true, true, true, false, true, true, false, false, true, true, false, true, false, true, false, true, true, true, false, false, true, false, true, false, true, false, true, false, true, true, false, true, true, true, true, true, true, false, false, false, false, true, false, false, false, true, true, false, false, false, true, true, true, true, true, false, false, false, false, false, false, true, true, true, true, false, false, false, false, true, false, false, true, true, false, true, true, true, true, true, true, true, false, true, false, true, false, false, true, false, false, false, true, false, false, false, true, false, true, false)
  val DOUBLE_RANGE_TEST = List(0.5400863228974659, 0.9394217902064828, 0.8364202846336797, -0.8288644453498977, 0.2471369358609381, 0.17377496409555726, -0.6301838412824818, -0.27580671245932953, 0.4489225129056176, 0.9619821361224845, -0.13578811322949647, 0.8133640273467722, -0.3539462513458851, 0.2420730163306788, -0.7164933321659801, 0.041999009742780036, 0.46503068567114525, 0.05727687654328961, -0.3951297472426596, -0.4131594269378398, 0.47430021052108384, -0.40251680921110555, 0.04809344319482389, -0.4385064967241501, 0.3875595999949768, -0.8747588690963135, 0.42999622880606947, -0.45711875049060646, 0.9869379789896175, 0.6427594687422935, -0.6009412922894006, 0.8598250849488462, 0.718020658288242, 0.6233039216226524, 0.49200382009077503, 0.5716431599138787, 0.4779376862861733, -0.5729132881724481, -0.46996926319137966, -0.514877796033542, -0.7625352677573534, 0.8250385364508737, -0.9200908584617253, -0.6833721696494217, -0.08253479820921839, 0.33795387084124595, 0.1003475393968678, -0.6235677243405395, -0.6930778897196248, -0.23732203593262735, 0.20714043134762616, 0.4468386301648317, 0.5769568086187333, 0.18194166721480398, 0.9669634704326457, -0.4931295374096669, -0.06268313589389063, -0.19085029156430333, -0.3760052654541466, -0.9917942419386745, -0.2039534448617717, 0.7102752651822317, 0.8885147513585601, 0.8922320305690306, 0.4371218532507022, -0.22021082314940776, -0.7041305494906878, -0.7798732293230011, -0.07912832866935093, 0.8569569265985288, -0.6923678917883163, -0.5621921933758189, 0.6260639830991455, 0.9708947985156098, -0.551771411603784, 0.6495302110537828, 0.05121984084974329, 0.9982834276467862, 0.1952560037438167, 0.6483517981381843, 0.7632783473845772, 0.9334004411336176, -0.3406985465918113, 0.8874685330006495, -0.10148099354110296, 0.4066366034740281, -0.503665408919217, -0.07853925634771408, 0.015354206506155155, -0.7725132181053254, -0.16157183815532883, -0.6061291381201677, 0.5303519124118503, -0.6500506456989326, -0.04463615720700176, -0.2305930804165297, 0.3680041879425082, -0.9487812077340818, 0.9868441349024655, -0.6785589669599619)
  val DOUBLE_TEST = List(0.770043161448733, 0.9697108951032414, 0.9182101423168398, 0.08556777732505116, 0.623568467930469, 0.5868874820477786, 0.18490807935875908, 0.36209664377033524, 0.7244612564528088, 0.9809910680612423, 0.43210594338525177, 0.9066820136733861, 0.32302687432705746, 0.6210365081653394, 0.14175333391700995, 0.52099950487139, 0.7325153428355726, 0.5286384382716448, 0.3024351263786702, 0.2934202865310801, 0.7371501052605419, 0.2987415953944472, 0.524046721597412, 0.28074675163792495, 0.6937797999974884, 0.06262056545184325, 0.7149981144030347, 0.27144062475469677, 0.9934689894948088, 0.8213797343711468, 0.19952935385529968, 0.9299125424744231, 0.859010329144121, 0.8116519608113262, 0.7460019100453875, 0.7858215799569394, 0.7389688431430866, 0.21354335591377593, 0.26501536840431017, 0.242561101983229, 0.11873236612132332, 0.9125192682254368, 0.03995457076913733, 0.15831391517528914, 0.4587326008953908, 0.668976935420623, 0.5501737696984339, 0.18821613782973023, 0.1534610551401876, 0.3813389820336863, 0.6035702156738131, 0.7234193150824159, 0.7884784043093667, 0.590970833607402, 0.9834817352163229, 0.25343523129516654, 0.4686584320530547, 0.40457485421784833, 0.3119973672729267, 0.004102879030662754, 0.39802327756911415, 0.8551376325911159, 0.94425737567928, 0.9461160152845153, 0.7185609266253511, 0.3898945884252961, 0.14793472525465612, 0.11006338533849946, 0.46043583566532453, 0.9284784632992644, 0.15381605410584187, 0.21890390331209053, 0.8130319915495727, 0.9854473992578049, 0.22411429419810802, 0.8247651055268914, 0.5256099204248716, 0.9991417138233931, 0.5976280018719083, 0.8241758990690922, 0.8816391736922886, 0.9667002205668088, 0.32965072670409434, 0.9437342665003248, 0.4492595032294485, 0.703318301737014, 0.24816729554039152, 0.46073037182614296, 0.5076771032530776, 0.11374339094733732, 0.4192140809223356, 0.19693543093991617, 0.7651759562059252, 0.17497467715053372, 0.4776819213964991, 0.38470345979173515, 0.6840020939712541, 0.025609396132959095, 0.9934220674512327, 0.16072051652001906)
  val LONG_TEST = List(-4241954996578871244l, -558735282347943651l, -1508756660734336358l, 1578446954249018780l, -6943936245327195908l, -7620580907819280329l, 3410952174022343530l, 6679504192470554453l, -5082792670653559847l, -350652725719535888l, 7970947723475865381l, -1721413009745314761l, 5958794004968174094l, -6990642601384425429l, 2614887420542783718l, -8835999762737100992l, -4934221017692232679l, -8695086072735722711l, 5578943176809710089l, 5412649096899536690l, -4848724524065549659l, 5510809839979344148l, -8779788161688994625l, 5178863536393745668l, -5648765583929023850l, 1155145653466224339l, -5257356727493315397l, 5007195696730884316l, -120475819916023534l, -3294962360084427422l, 3680666998223282921l, -1292885399151739729l, -2600800376376092253l, -3474407862519924405l, -4685437759201474202l, -3950894504376018504l, -4815175111021690137l, 3939179880435287463l, 4888670844411151511l, 4474462732463301064l, 2190225638720209478l, -1613734771484127550l, 737031643098635475l, 2920376426110117155l, 8462122913918722858l, -6106297772965382272l, -8297829370712350200l, 3471975060971684829l, 2830856899826918407l, 7034462363631301785l, -7312838824656994129l, -5102013132494375179l, -3901884570438358836l, -7545256264940437054l, -304707957988349915l, 4675054878463396587l, 8645222129658652825l, 7463088593495996347l, 5755335383948743733l, 75684700580366801l, 7342233797818254736l, -2672238890676709530l, -1028270121309537765l, -993984246962344343l, -5191634621327456136l, 7192285601367995443l, 2728914065549516427l, 2030311093675509882l, 8493541888825696940l, -1319339633558648675l, 2837405267143949177l, 4038064253578824088l, -3448950847059621621l, -268448003764368206l, 4134178863160133214l, -3232513194526581241l, -8750952543695781371l, -15832514794655227l, -7422453340243833539l, -3243382240526413120l, -2183371856117630013l, -614272649530748372l, 6080982518309312290l, -1037919535267640374l, 8287374924631676845l, -5472811309297954641l, 4577878579720849614l, 8498975104004365808l, -9081754416593660604l, 2098195182075056968l, 7733134910798833140l, 3632817733000630181l, -4331738945489722632l, 3227713049359381556l, 8811676267786490911l, 7096526416083856862l, -5829132420892189990l, 472409940358728322l, -121341332641833498l, 2964770210021618661l)
  val FLOAT_TEST = List(0.770043134689331f, 0.9697108864784241f, 0.9182101488113403f, 0.08556777983903885f, 0.6235684752464294f, 0.5868874788284302f, 0.18490807712078094f, 0.3620966374874115f, 0.7244612574577332f, 0.9809910655021667f, 0.4321059286594391f, 0.906682014465332f, 0.3230268657207489f, 0.6210365295410156f, 0.14175333082675934f, 0.5209994912147522f, 0.7325153350830078f, 0.5286384224891663f, 0.30243512988090515f, 0.29342028498649597f, 0.7371501326560974f, 0.2987416088581085f, 0.5240467190742493f, 0.2807467579841614f, 0.6937798261642456f, 0.06262056529521942f, 0.7149981260299683f, 0.27144062519073486f, 0.9934689998626709f, 0.8213797211647034f, 0.19952934980392456f, 0.9299125671386719f, 0.8590103387832642f, 0.8116519451141357f, 0.7460018992424011f, 0.7858215570449829f, 0.7389688491821289f, 0.2135433554649353f, 0.2650153636932373f, 0.24256110191345215f, 0.11873236298561096f, 0.9125192761421204f, 0.039954569190740585f, 0.15831391513347626f, 0.45873260498046875f, 0.6689769625663757f, 0.5501737594604492f, 0.18821613490581512f, 0.1534610539674759f, 0.3813389837741852f, 0.6035702228546143f, 0.7234193086624146f, 0.788478434085846f, 0.5909708142280579f, 0.983481764793396f, 0.2534352242946625f, 0.4686584174633026f, 0.40457484126091003f, 0.31199735403060913f, 0.004102879203855991f, 0.3980232775211334f, 0.8551376461982727f, 0.944257378578186f, 0.946116030216217f, 0.7185609340667725f, 0.3898945748806f, 0.1479347199201584f, 0.11006338894367218f, 0.4604358375072479f, 0.928478479385376f, 0.15381605923175812f, 0.21890389919281006f, 0.8130319714546204f, 0.9854474067687988f, 0.2241142988204956f, 0.8247650861740112f, 0.5256099104881287f, 0.9991416931152344f, 0.5976279973983765f, 0.8241758942604065f, 0.8816391825675964f, 0.9667001962661743f, 0.32965072989463806f, 0.9437342882156372f, 0.449259489774704f, 0.7033182978630066f, 0.24816729128360748f, 0.4607303738594055f, 0.5076770782470703f, 0.11374339461326599f, 0.41921406984329224f, 0.19693543016910553f, 0.7651759386062622f, 0.17497467994689941f, 0.4776819348335266f, 0.38470345735549927f, 0.6840021014213562f, 0.025609396398067474f, 0.9934220910072327f, 0.16072051227092743f)
  val GAUSSIAN_TEST = List(1.7899041966542883, 1.2585756816338702, -1.1206717795981727, -0.4904740157219745, -0.14461942104491454, 0.8662631207994318, -1.5190747612788353, 1.0389346068683787, -1.1498444386639322, 0.06740094515065313, 1.7283455004009856, 0.21287677329883323, -1.0336609142405464, -1.080826624560349, 1.050616143303797, -0.8916096774313438, 0.19725444623632904, -1.7985270015282295, 0.1703113829905396, -0.38440898582041194, 0.9353350034707967, -0.99433236720206, 0.3391626614565248, 0.2944224717124545, 0.6929217124348677, 0.8050830930461521, 0.6933818219181271, -0.8311704034911747, -0.8098978362987483, -0.8872886923160865, -0.4875701759474343, 1.9964455216875876, 0.21540252052935746, -1.3385286809324626, -1.0555022989639713, -0.36142251576230816, 0.707882725905659, 1.5270285260254028, 1.352223639260844, 0.4264198284848863, -0.7906536980465801, -2.4072900413600955, -0.3035872543181274, 1.0572536184073573, 1.5097542761036635, -0.7605756367972022, -0.07124962883490966, 0.7716308934413254, -0.5252218070667648, -0.42647211580105004, -0.5177251153920911, 0.6094518425502327, 0.002058633872215309, 0.04012312502597662, 0.3601274286608172, 1.195810942835173, -0.1613059668519126, 0.4201778117293529, -0.4516008757399804, 1.8095747768021542, -1.6221403576376516, -0.25294907119760157, 0.020183601639556775, -1.0154936400835437, -0.351783590239092, -1.3196995639268005, 0.5298137482923607, -0.6493910196559617, -0.45748121440799155, -2.3633755471782836, -0.04678951441148152, 1.3119045569766876, -0.2536017418485992, -1.2126062158078592, -0.03351595821894028, -1.1272107576105956, -0.15015521500707846, -0.04112252318466596, -0.5650115913345137, 0.9751031152901832, 0.13550620655642473, -0.39830720129180414, -2.2343533158609787, 2.526308537405164, -0.721842826829416, 1.5768808905922207, -0.05502870423192846, -2.6290221410630545, 0.5036885965506965, -0.792296056280221, -0.7094988638426636, -2.3917297339986616, -0.036345747920887725, -0.10792273558745669, 0.995450822055992, 1.8834937012786983, -0.2009656658436437, 0.11393909868838889, 0.5949150513310623, -0.0788764631822578)
  val INT_TEST = List(-877062092, -1809032931, -1871912294, 1422876060, -2108681988, 927914039, 645053290, 1810929493, -289649703, 737603312, -50540763, -228262857, -1814367730, -1866151893, 890704102, -358709440, -2060442599, 254022441, -1009450487, 445196082, 693703333, 414331156, 727252159, -1829178108, 1047880342, 45143763, 943731899, -125679396, 1306634514, -488469150, 1167729385, 1480948911, 1516673443, 229439819, -1181218458, -1986012744, -1740635417, 129369511, 1357874327, 20111816, 903807558, 2013138626, -618799917, 12051747, -1177443542, 765704064, -1344069112, 842761181, 338011143, -501664615, -2069725009, 1850439413, 7448780, 1290748354, 64923685, 2017757931, -89757543, -560384069, -478129099, -1928967727, 13829520, 372971366, -835552741, -8802711, -2144843656, -390974413, 1537564299, -1039120262, -530898260, -341538659, -1477444743, 1187301784, 1497008395, 2130070706, -1332312482, 1283120647, -1430896123, 1673753093, 1289407805, 1386009280, 1736833987, -1585753556, -919611614, -1964045366, -416901203, 1116606639, 1226934478, -586048016, -1382443708, -1056631992, -1101650444, 222171045, 777790200, -805997516, 422007839, 702197214, -2147345702, 2071071362, 1800379878, 1224717285)
  val INT_RANGE_TEST = List(7, 9, 9, 0, 6, 5, 1, 3, 7, 9, 4, 9, 3, 6, 1, 5, 7, 5, 3, 2, 7, 2, 5, 2, 6, 0, 7, 2, 9, 8, 1, 9, 8, 8, 7, 7, 7, 2, 2, 2, 1, 9, 0, 1, 4, 6, 5, 1, 1, 3, 6, 7, 7, 5, 9, 2, 4, 4, 3, 0, 3, 8, 9, 9, 7, 3, 1, 1, 4, 9, 1, 2, 8, 9, 2, 8, 5, 9, 5, 8, 8, 9, 3, 9, 4, 7, 2, 4, 5, 1, 4, 1, 7, 1, 4, 3, 6, 0, 9, 1)
}

class TestMultiplyWithCarryGenerateRandom extends Suite with ShouldMatchers {
  import TestMultiplyWithCarryGenerateRandom._
  def testGenerateBoolean() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aBOOLEAN_TEST <- BOOLEAN_TEST) {
      val g: Boolean = rnd.nextBoolean
      assert(g === aBOOLEAN_TEST)
    }
  }

  def testDoubleRange() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aDOUBLE_RANGE_TEST <- DOUBLE_RANGE_TEST) {
      val g: Double = rnd.nextDouble(-1, 1)
      g should be (aDOUBLE_RANGE_TEST plusOrMinus AIFH.DEFAULT_PRECISION)
    }
  }

  def testDouble() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aDOUBLE_TEST <- DOUBLE_TEST) {
      val g: Double = rnd.nextDouble()
      g should be (aDOUBLE_TEST plusOrMinus AIFH.DEFAULT_PRECISION)
    }
  }

  def testLong() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aLONG_TEST <- LONG_TEST) {
      val l: Long = rnd.nextLong
      assert(l === aLONG_TEST)
    }
  }

  def testFloat() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aFLOAT_TEST <- FLOAT_TEST) {
      val l: Float = rnd.nextFloat
      l should be (aFLOAT_TEST plusOrMinus AIFH.DEFAULT_PRECISION.toFloat)
    }
  }

  def testGaussianFloat() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aGAUSSIAN_TEST <- GAUSSIAN_TEST) {
      val g: Double = rnd.nextGaussian
      g should be (aGAUSSIAN_TEST plusOrMinus AIFH.DEFAULT_PRECISION)
    }
  }

  def testInt() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aINT_TEST <- INT_TEST) {
      val g = rnd.nextInt
      assert(g === aINT_TEST)
    }
  }

  def testIntRange() {
    val rnd = new MultiplyWithCarryGenerateRandom(1)
    for (aINT_RANGE_TEST <- INT_RANGE_TEST) {
      val g = rnd.nextInt(0, 10)
      assert(g === aINT_RANGE_TEST)
    }
  }
}